# -*- coding: iso-8859-2 -*-

import re
import string

from authorshipanalyzer.slot import Filler
from authorshipanalyzer.textutils import Splitter

class DocumentFeaturesFiller(Filler):
    '''
    Fill slot with character based features
    '''
       
    def __init__(self):
        self.splitter = Splitter()

    def fill(self, slot):
        '''
        Fill a slot
        '''

#        lines = slot.message.text.split('\n')
#        lineNumber = len(lines)
#        blankLineNumber = 0.0
#        
#        for line in lines:
#            if line.strip() == "":
#                blankLineNumber += 1.0
#                
#        slot.dBlankLines = blankLineNumber / lineNumber
        
        posList = self.splitter.getPosList(slot.text, False)
        
        sYes = 0.0
        sNo = 0.0
        isVerb = False
        for pos in posList:
            if pos == "verb":
                isVerb = True
                
            if pos == "?" or pos == "!" or pos == ".":
                if isVerb:
                    sYes += 1.0
                    isVerb = False
                else:
                    sNo += 1.0
         
#        print str(sYes) + " " + str(sNo) + " <-------------"            
        if sNo > 0.0:       
            slot.dSentences = sYes / (sYes + sNo)  #True
        else:
            slot.dSentences = 1.0 #True       
        